<?php
require($_SERVER['DOCUMENT_ROOT'] . '/setting.php');
$adminPath = $website_array['admin'] ?? 'admin';
$requestPath = trim($_SERVER['REQUEST_URI'], '/');
$parts = explode('?', $requestPath, 2);
$basePath = $parts[0];
$queryString = isset($parts[1]) ? $parts[1] : '';
$baseParts = explode('/', $basePath);
$firstLevelDirectory = $baseParts[0] ?? null;
$remainingPath = '';
if ($firstLevelDirectory && count($baseParts) > 1) {
    $remainingPath = '/' . implode('/', array_slice($baseParts, 1));
}
$cok_header_location = true;

function handleError($errno, $errstr, $errfile, $errline)
{
    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler('handleError');

if ($firstLevelDirectory === 'uploads') {
    include $_SERVER['DOCUMENT_ROOT'] . '/404.php';
    exit;
}
if ($firstLevelDirectory === 'share') {
    if ($remainingPath === '' || $remainingPath === 'null') {
        include $_SERVER['DOCUMENT_ROOT'] . '/404.php';
        exit;
    }
    $newremainpath2 = ltrim($remainingPath, '/');
    require($_SERVER['DOCUMENT_ROOT'] . '/cofd/functions.php');
    $newremainpath = encrypt($newremainpath2, 'D', 'yhsdylpo9342');
    if ($newremainpath === 'null' || $newremainpath === '') {
        include $_SERVER['DOCUMENT_ROOT'] . '/404.php';
        exit;
    }
    include($_SERVER['DOCUMENT_ROOT'].'/share/index.php');
    exit;
}
if ($firstLevelDirectory === $adminPath && $cok_header_location) {
    if ($remainingPath === '' || $remainingPath === 'null') {
        $remainingPath = 'index.php';
    }
    $fullPath = $_SERVER['DOCUMENT_ROOT'] . '/admin/' . $remainingPath;
    if (!file_exists($fullPath)) {
        include $_SERVER['DOCUMENT_ROOT'] . '/404.php';
        exit;
    }
    try {
        $_SERVER['QUERY_STRING'] = $queryString;
        include $fullPath;
    } catch (ErrorException $e) {
        include $_SERVER['DOCUMENT_ROOT'] . '/404.php';
        exit;
    }
    exit;
} else {
    include $_SERVER['DOCUMENT_ROOT'] . '/404.php';
    exit;
}
restore_error_handler();
